package com.android.clinic.app.ui.personal;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;

import com.android.clinic.app.R;
import com.android.clinic.app.base.BaseActivity;

/**
 * Created by cheng on 2018/2/5.
 * 过敏史
 */
public class AllergyHistoryActivity extends BaseActivity {

    public static final int ALLERGY_CODE = 998;
    private EditText etAllergy;
    private String type = "";

    @Override
    protected int getLayoutResId() {
        return R.layout.activity_allergy_history;
    }

    @Override
    protected void initView(@Nullable Bundle savedInstanceState) {
        setTitleBarTitle("过敏史/疾病史");
        setTitleBarLeftText("取消");
        setTitleBarRightText("保存");

        type = this.getIntent().getStringExtra("type");
        String allergy = this.getIntent().getStringExtra("allergy");
        String history = this.getIntent().getStringExtra("history");

        etAllergy = (EditText) findViewById(R.id.et_allergy);

        if (type.equals("0")) {
            if (!TextUtils.isEmpty(allergy) && !allergy.equals("请填写")) {
                etAllergy.setText(allergy);
            }
        } else {
            if (!TextUtils.isEmpty(history) && !history.equals("请填写")) {
                etAllergy.setText(history);
            }
        }
        etAllergy.setHint("多行输入");

    }

    @Override
    protected void onRightClickListener(View v) {
        if (etAllergy.getText().toString().trim().length() == 0) {
            showToast("内容不能为空!");
            return;
        }
        hideKeyboard();
        Intent intent = new Intent();
        if ("0".equals(type)) {  // 过敏史
            intent.putExtra("allergy", etAllergy.getText().toString().trim());
        } else {  // 既往病史
            intent.putExtra("history", etAllergy.getText().toString().trim());
        }
        setResult(RESULT_OK, intent);
        finish();
    }
}
